package com.fzb.forum4j.controller;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.fzb.forum4j.po.Comment;
import com.fzb.forum4j.service.api.ICommentService;
import com.fzb.forum4j.service.api.IUserService;

@Controller("commentAction")
public class CommentAction extends CommonsAction<Comment>{
	
	
	/**
	 * 评论管理
	 */
	private static final long serialVersionUID = 1L;
	@Resource(name="userServiceImpl")
	private IUserService userServiceImpl;
	
	@Resource(name="commentServiceImpl")
	private ICommentService commentService;
	
	@Override
	public Object getModel() {
		getQmd().setT(getT());
		getT().setUser(getUserMsg());
		return getQmd();
	}
	
	public void validateAdd(){
		if(getT().getContent()==null || getT().getContent().length()==0){
			addFieldError("error", "用户名不能为空");
		}
		else{
			getT().setUser(getUserMsg());
			getT().setUserIp(getRequest().getRemoteAddr());
		}
	}
	@Override
	public String add() {
		// 先处理是否有@他人
		getT().setCommTime(new Date());
		userServiceImpl.disposeCommentContext(getQmd());
		if(getT().getReplyComm().getCommentId()==null || getT().getReplyComm().getCommentId()==0){
			getT().setReplyComm(null);
		}
		String str=super.add();
		if(getT().getForward()!=null){
			return "go_forward";
		}
		return str;
	}
	@Override
	public String list() {
		commentService.getList(getQmd());
		return "list";
	}
}
